<template>
  <h1>猜数字练习</h1>
  <input type="text" placeholder="猜一猜" v-model="num">
  <button @click="guessNum">猜</button>
  <h4>你的猜数是:{{result}}</h4>

</template>

<script setup>
import { ref } from 'vue'
let x = parseInt(Math.random() * 100)+1;
console.log("小炒:"+x);
const num = ref('');
const result = ref('');
const guessNum = ()=>{
  if(num.value.trim()=='' || isNaN(num.value)){
    num.value = '';
    alert('请输入数字');
    return;
  }
  if(num.value > x){
  result.value = "猜大了";
  }else if(num.value < x){
    result.value = "猜小了";
  }else {
    result.value = "恭喜你猜对了";
  }
}
</script>


<style scoped>

</style>